require 'chess-data'
require 'minitest/autorun'

describe ChessData::Database do
  it "correctly reads a test file" do
    database = ChessData::Database.from_file "test/data/games1.pgn"
    game = database[0]
    _(game.event).must_equal "F/S Return Match"
    _(game.site).must_equal "Belgrade, Serbia JUG"
    _(game.date).must_equal "1992.11.04"
    _(game.round).must_equal "29"
    _(game.white).must_equal "Fischer, Robert J."
    _(game.black).must_equal "Spassky, Boris V."
    _(game.half_moves).must_equal 85

    game = database[1]
    _(game.event).must_equal "8th RUS-CHN Summit Men Classical"
    _(game.date).must_equal "2012.07.02"
    _(game.half_moves).must_equal 103
  end

  it "correctly reads a test file with missing gap between games" do
    database = ChessData::Database.from_file "test/data/games2.pgn"
    game = database[0]
    _(game.event).must_equal "F/S Return Match"
    _(game.site).must_equal "Belgrade, Serbia JUG"
    _(game.date).must_equal "1992.11.04"
    _(game.round).must_equal "29"
    _(game.white).must_equal "Fischer, Robert J."
    _(game.black).must_equal "Spassky, Boris V."
    _(game.half_moves).must_equal 85

    game = database[1]
    _(game.event).must_equal "8th RUS-CHN Summit Men Classical"
    _(game.date).must_equal "2012.07.02"
    _(game.half_moves).must_equal 103
  end

  it "correctly reads a test file with acute accent (for forward tick) in header" do
    ChessData::Database.from_file "test/data/games3.pgn"
  end
end

